﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="news_page_set.aspx.cs"
    Inherits="Ccit.OA.NewsCenter.news_page_set" %>

<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>信息中心-页面设置</title>

    <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>

    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jsonlib.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jcontrol.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jwindow.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
    
      //根据选择列数，判断文本框的可用不可用
      function doRadioClick(operType) {
            /* cell width text */
            var ctrlTxtTwoCell = document.getElementById("txtTwoCell");
            var ctrlTxtThreeCell = document.getElementById("txtThreeCell");
            
            /* two cell select、remove plate item button */
            var btn_twoCellSel = document.getElementById("btnTwoCell_Sel");
            var btn_twoCellUnSel = document.getElementById("btnTwoCell_unSel");
            
            /* three cell select、remove plate item button */
            var btn_threeCellSel = document.getElementById("btnThreeCell_Sel");
            var btn_threeCellUnSel = document.getElementById("btnThreeCell_unSel");
            
            switch(operType) {                
                case "1" : //一列
                    ctrlTxtTwoCell.value = "";
                    ctrlTxtThreeCell.value = "";
                    ctrlTxtTwoCell.disabled = "disabled";
                    ctrlTxtThreeCell.disabled = "disabled";
                    
                    btn_twoCellSel.disabled = "disabled";
                    btn_twoCellUnSel.disabled = "disabled";
                    doUnSelPlate("2","2");  //移除板块2的所有板块
                    
                    btn_threeCellSel.disabled = "disabled";
                    btn_threeCellUnSel.disabled = "disabled";
                    doUnSelPlate("3","2");
                    break;
                case "2":  // 2列
                    ctrlTxtTwoCell.disabled = "";
                    
                    ctrlTxtThreeCell.value = "";
                    ctrlTxtThreeCell.disabled = "disabled";
                    
                    btn_twoCellSel.disabled = "";
                    btn_twoCellUnSel.disabled = "";
                    
                    btn_threeCellSel.disabled = "disabled";
                    btn_threeCellUnSel.disabled = "disabled";
                    doUnSelPlate("3","2");   //移除已选板块3的所有板块
                    break;
                case "3":
                    ctrlTxtTwoCell.disabled = "";
                    ctrlTxtThreeCell.disabled = "";
                    
                    btn_twoCellSel.disabled = "";
                    btn_twoCellUnSel.disabled = "";
                    
                    btn_threeCellSel.disabled = "";
                    btn_threeCellUnSel.disabled = "";
                    break;
            }
      }
      
      //选中移动按钮(参数1: 列数，参数2: 移动类型 )
      function doSelPlate(cellIndex,moveType) {
            var unselCtrl = new ListBox("lstUnSelPlate");  //lstUnSelPlate 待选板块
            
            switch(cellIndex) {
                case "1" :
                    var oneSelCtrl = new ListBox("lstOneCellSel");  //一列已选板块
                    selPlate(unselCtrl,oneSelCtrl,moveType);
                    oneSelCtrl = null;
                    break;
                case "2":
                    var twoSelCtrl = new ListBox("lstTwoCellSel");
                    selPlate(unselCtrl,twoSelCtrl,moveType);
                    twoSelCtrl = null;
                    break;
                case "3":
                    var threeSelCtrl = new ListBox("lstThreeCellSel");   
                    selPlate(unselCtrl,threeSelCtrl,moveType);
                    threeSelCtrl = null;
                    break;
            }
      }
      
      //参数1：要移除项板块，参数2:添加板块，参数3：移动类型
      function selPlate(lsbOrigin,lsbDest,moveType) {    
            
            var moveArray;  // move items
            
            // move type: [1]: move selected items [2]: move all
            if(moveType == "2") //移除所有
            {
                moveArray = lsbOrigin.moveSelItem(true,true);              
            }
            else  //移除选定项 
                moveArray = lsbOrigin.moveSelItem(false,true);
                
            lsbDest.addItems(moveArray);            
            moveArray = null;
        }
      
      
      //不选择板块
      function doUnSelPlate(cellIndex,moveType) {                        
            var unselCtrl = new ListBox("lstUnSelPlate"); //待选板块
            switch(cellIndex) {
                case "1" :
                    var oneSelCtrl = new ListBox("lstOneCellSel");  //一列已选板块
                    selPlate(oneSelCtrl,unselCtrl,moveType); 
                    oneSelCtrl = null;
                    break;
                case "2":
                    var twoSelCtrl = new ListBox("lstTwoCellSel");  //二列已选板块
                    selPlate(twoSelCtrl,unselCtrl,moveType);
                    twoSelCtrl = null;
                    break;
                case "3":
                     var threeSelCtrl = new ListBox("lstThreeCellSel");  //三列已选板块
                    selPlate(threeSelCtrl,unselCtrl,moveType);
                    threeSelCtrl = null;
                    break;
            }
            unselCtrl = null;
        }
        
        function checkForm() {
            var ctrlOneCellWidth = $get("txtOneCell");
            var ctrlTwoCellWidth = $get("txtTwoCell");
            var ctrlThreeCellWidth = $get("txtThreeCell");
            var cellCount = getCellCount();
            
            if(jQuery.trim(ctrlOneCellWidth.value) == "") {
                alert("一列的宽度不能为空!");
                return false;
            }
            
            if(!ctrlOneCellWidth.value.IsNumber()) {
                alert("一列宽度输入非法,必须为数字!");
                return false;
            }
            if(ctrlTwoCellWidth.value!=""&&!ctrlTwoCellWidth.value.IsNumber()) {
                alert("二列宽度输入非法,必须为数字!");
                return false;
            }
            if(ctrlThreeCellWidth.value!=""&&!ctrlThreeCellWidth.value.IsNumber()) {
                alert("三列宽度输入非法,必须为数字!");
                return false;
            }            
            switch(cellCount) {
                case "1":                
                    break;
                case "2":
                    if(parseFloat(ctrlOneCellWidth.value) >= 100) {
                        alert("一列宽度输入非法，宽度应设置在[1-99]范围内!");
                        return false;
                    }
                    
                    if(jQuery.trim(ctrlTwoCellWidth.value) == "") {
                        ctrlTwoCellWidth.value = 100 - parseFloat(ctrlOneCellWidth.value);
                        return true;
                    }
                    else {                    
                        if(parseFloat(ctrlTwoCellWidth.value) >= 100){
                            alert("二列宽度输入非法,宽度应设置在[1-99]范围内!");
                            return false;
                        }
                        
                        if((parseFloat(ctrlOneCellWidth.value) + parseFloat(ctrlTwoCellWidth.value)) > 100) {
                            alert("一列宽度与二列宽度之和大于100,请重新输入!");
                            return false;
                        }
                    }
                    
                    
                    break;
                case "3":
                    if(parseFloat(ctrlOneCellWidth.value) >= 100) {
                        alert("一列宽度输入非法，宽度应设置在[1-99]范围内!");
                        return false;
                    }
                    
                    if(jQuery.trim(ctrlTwoCellWidth.value) == "") {
                        alert("二列的宽度不能为空!");
                        return false;
                    }
                    else {
                        if(parseFloat(ctrlTwoCellWidth.value) >= 100){
                            alert("二列宽度输入非法,宽度应设置在[1-99]范围内!");
                            return false;
                        }
                    }
                    
                    if(jQuery.trim(ctrlThreeCellWidth.value) == "") {
                        ctrlThreeCellWidth.value = 100 - parseFloat(ctrlOneCellWidth.value) - parseFloat(ctrlTwoCellWidth.value);
                        return true;
                    }
                    else {
                        if(parseFloat(ctrlThreeCellWidth.value) >= 100){
                            alert("三列宽度输入非法,宽度应设置在[1-99]范围内!");
                            return false;
                        }
                    
                        if((parseFloat(ctrlOneCellWidth.value) + parseFloat(ctrlTwoCellWidth.value) + parseFloat(ctrlThreeCellWidth.value)) > 100) {
                            alert("一列宽度与二列宽度之和大于100,请重新输入!");
                            return false;
                        }
                    }
                    
                    break;
            }        
            return true;
        }
        
        
        //确定按钮
        function doSave(){
           if(!checkForm()) return false;
           
           MsLayout = {};  //布局设置表
           MsLayout.CellCount = getCellCount();
           MsLayout.OneCellWidth = $get("txtOneCell").value;
           MsLayout.TwoCellWidth = $get("txtTwoCell").value;
           MsLayout.ThreeCellWidth = $get("txtThreeCell").value;
           
           //待选板块
           var unselPlateArray = getCellSelPlates($get("lstUnSelPlate"));
           //已选板块
           var selOneplateArray = getCellSelPlates($get("lstOneCellSel"));
           var selTwoPlateArray = getCellSelPlates($get("lstTwoCellSel"));
           var selThreePlateArray = getCellSelPlates($get("lstThreeCellSel"));
           
           var unSelPlate = "";
           for(var i=0;i<unselPlateArray.length;i++){
             if(i==0)
               unSelPlate = unselPlateArray[i].PlateId;
             else
               unSelPlate +="," + unselPlateArray[i].PlateId;
           }
           
           var selOnePlate="";
           for(var i=0;i<selOneplateArray.length;i++){
             if(i==0)
               selOnePlate = selOneplateArray[i].PlateId;
             else
               selOnePlate +="," + selOneplateArray[i].PlateId;
           }
           
           var selTwoPlate="";
           for(var i=0;i<selTwoPlateArray.length;i++){
               if(i==0)
                  selTwoPlate = selTwoPlateArray[i].PlateId ;
               else
                  selTwoPlate +="," + selTwoPlateArray[i].PlateId;
           }
           
           var selThreePlate=""; 
           for(var i=0;i<selThreePlateArray.length;i++){
              if(i==0)
                 selThreePlate += selThreePlateArray[i].PlateId;
              else
                 selThreePlate +="," + selThreePlateArray[i].PlateId;
           }
           
           var Type = document.getElementById("_hidType").value;
           var vSysUserId = document.getElementById("_hidSysUserId").value;
           var jsonExpr = JSON.stringify(MsLayout,function (key,value) { return value;});
           PageMethods.SavePlate(jsonExpr,selOnePlate,selTwoPlate,selThreePlate,unSelPlate,Type,vSysUserId,ClientCallBack);
        }
        
        function ClientCallBack(vResult){
           eval("var vResultObj="+vResult);
           if(vResultObj.resFlag > 0){
               alert(vResultObj.resMes);
               var vPageParam = "Type="+$get("_hidType").value;
		       var encodeParam = base64encode(vPageParam);
               document.location = "news_page_browse.aspx?"+encodeParam;
           }
        }
        
        //获取选择的列数
        function getCellCount() {
            var cellCount = getRbtnListCheckValue("rdCell");                       
            cellCount = (cellCount == "") ? "2" : cellCount;
            return cellCount;
        }
        function getRbtnListCheckValue(ctrlId) {
            var rdCtrl = new RadioList(ctrlId);
            var checkValue = rdCtrl.checkedValue;           
            rdCtrl = null;
            return checkValue;
        }
        //获取选中列里的项
        function getCellSelPlates(lsbSel) {
            var oOptions = lsbSel.options;
            var iLen = oOptions.length;
            var oOption;            
            
            var plateArray = [];
            var plate;
            
            for(var i = 0; i < iLen; i ++) {
                oOption = oOptions[i];
                plate = {};
                plate.PlateId = oOption.value;
                plate.PlateName = oOption.innerText;
                
                plateArray.push(plate);
            }
           
            return plateArray;
        }
        
        //取消
        function doClose(){
           var vPageParam = "Type="+$get("_hidType").value;
		   var encodeParam = base64encode(vPageParam);
           document.location="news_page_browse.aspx?"+encodeParam;
        }
    </script>

</head>
<body>
    <ccit:ActionForm ID="form1" runat="server">
        <input type="hidden" id="_hidUserId" runat="server" />
        <input type="hidden" id="_hidSysUserId" runat="server" />
        <input type="hidden" id="_hidSelPlateId" runat="server" />
        <input type="hidden" id="_hidType" runat="server" />
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <table class="tbToolbar" cellpadding="0" cellspacing="0" width="98%" align="center">
            <tr>
                <td align="left">
                    <div class="tbSeparator">
                    </div>
                </td>
                <td class="titlebar" width="100%">
                    信息中心布局设置
                </td>
            </tr>
        </table>
        <table class="tableborder" cellpadding="0" cellspacing="0" width="98%" align="center">
            <tr>
                <td width="10%" class="pformleft" align="center">
                    <nobr>列数</nobr>
                </td>
                <td class="pformright">
                    <input type="radio" id="rdOne" name="rdCell" value="1" class="radio" onclick="doRadioClick('1')" runat="server" />一列 &nbsp;&nbsp;
                    <input type="radio" id="rdTwo" name="rdCell" value="2" class="radio" onclick="doRadioClick('2')" runat="server" />二列 &nbsp;&nbsp;
                    <input type="radio" id="rdThree" name="rdCell" value="3" class="radio" onclick="doRadioClick('3')" runat="server" />三列
                </td>
            </tr>
        </table>
        <table class="tableborder_mid" cellpadding="0" cellspacing="5" width="98%" align="center">
            <tr>
                <td colspan="2" align="center">
                    <fieldset id="fld" title="首页列宽度">
                        <legend><strong>列宽度设置</strong></legend>
                        <table cellpadding="0" cellspacing="0" width="96%" align="center">
                            <tr>
                                <td width="10%" align="center">
                                    <nobr>
                                        一列:
                                    </nobr>
                                </td>
                                <td align="left" width="24%">
                                    <asp:TextBox ID="txtOneCell" CssClass="input" Width="40%" runat="server"></asp:TextBox>&nbsp;%
                                </td>
                                <td width="10%" align="center">
                                    <nobr>
                                        二列:
                                    </nobr>
                                </td>
                                <td align="left" width="23%">
                                    <asp:TextBox ID="txtTwoCell" CssClass="input" Width="40%" runat="server"></asp:TextBox>&nbsp;%
                                </td>
                                <td width="10%" align="center">
                                    <nobr>
                                        三列:
                                    </nobr>
                                </td>
                                <td align="left" width="23%">
                                    <asp:TextBox ID="txtThreeCell" CssClass="input" Width="40%" runat="server"></asp:TextBox>&nbsp;%
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                </td>
            </tr>
        </table>
        <table class="tableborder_header" cellpadding="1" cellspacing="0" width="98%" align="center">
            <tr>
                <td width="50%" align="center">
                    <table cellpadding="3" cellspacing="0" width="98%" align="center">
                        <tr>
                            <td align="center">
                                <nobr>
                                    <strong>待选窗口</strong>
                                </nobr>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" valign="middle">
                                <asp:ListBox ID="lstUnSelPlate" SelectionMode="Multiple" Width="100%" Rows="18" runat="server"></asp:ListBox>
                            </td>
                        </tr>
                    </table>
                </td>
                <td align="center">
                    <table cellpadding="1" cellspacing="0" width="98%" align="center">
                        <tr>
                            <td align="center">
                                <nobr>
                                    <strong>已选窗口</strong>
                                </nobr>
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <fieldset id="fsOne" title="一列已选版块">
                                    <legend><strong>一列已选窗口</strong></legend>
                                    <table cellpadding="2" cellspacing="2" width="99%" align="center">
                                        <tr>
                                            <td width="10%" align="center" valign="middle">
                                                <input type="button" id="btnOneCell_Sel" onclick="doSelPlate('1','1')" value=">>" style="width: 32px" class="button" /><br />
                                                <br />
                                                <input type="button" id="btnOneCell_unSel" onclick="doUnSelPlate('1','1')" value="<<" style="width: 32px" class="button" />
                                            </td>
                                            <td width="90%">
                                                <!--ondblclick 事件会在对象被双击时发生-->
                                                <asp:ListBox ID="lstOneCellSel" Width="98%"  Rows="4" SelectionMode="Multiple" ondblclick="doUnSelPlate('1')" runat="server"></asp:ListBox>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <fieldset id="fsTwo" title="二列已选版块">
                                    <legend><strong>二列已选窗口</strong></legend>
                                    <table cellpadding="2" cellspacing="2" width="99%" align="center">
                                        <tr>
                                            <td width="10%" align="center" valign="middle">
                                                <input type="button" id="btnTwoCell_Sel" onclick="doSelPlate('2','1')" value=">>" style="width: 32px" class="button" /><br />
                                                <br />
                                                <input type="button" id="btnTwoCell_unSel" onclick="doUnSelPlate('2','1')" value="<<" style="width: 32px" class="button" />
                                            </td>
                                            <td>
                                                <asp:ListBox ID="lstTwoCellSel" Width="98%"  Rows="4" SelectionMode="Multiple" ondblclick="doUnSelPlate('2')" runat="server"></asp:ListBox>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <fieldset id="fsThree" title="三列已选版块">
                                    <legend><strong>三列已选窗口</strong></legend>
                                    <table cellpadding="2" cellspacing="2" width="99%" align="center">
                                        <tr>
                                            <td width="10%" align="center" valign="middle">
                                                <input type="button" id="btnThreeCell_Sel" onclick="doSelPlate('3','1')" value=">>" style="width: 32px" class="button" /><br />
                                                <br />
                                                <input type="button" id="btnThreeCell_unSel" onclick="doUnSelPlate('3','1')" value="<<" style="width: 32px" class="button" />
                                            </td>
                                            <td>
                                                <asp:ListBox ID="lstThreeCellSel" Width="98%" Rows="4" SelectionMode="Multiple" ondblclick="doUnSelPlate('3')" runat="server"></asp:ListBox>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr class="pformstrip">
                <td align="center" colspan="2">
                    <input type="button" id="btnSave" class="button" value="确定" onclick="doSave()" />
                    <span id="spEmpty2">&nbsp;</span>
                    <input type="button" id="btnCancle" class="button" value="取消" onclick="doClose()" />
                </td>
            </tr>
        </table>
        <asp:LinkButton ID="lnbCallBack" Style="display: none" runat="server"></asp:LinkButton>
    </ccit:ActionForm>
</body>
</html>
